#include "point.h"

Point::Point(const QPointF &point, const QColor &color)
    : MyShape(point, color) {}

QRectF Point::boundingRect() const
{
    return QRectF(startPoint_.x() - hitRadius_, startPoint_.y() - hitRadius_,
                  2 * hitRadius_, 2 * hitRadius_);
}

void Point::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    painter->setPen(QPen(color_, penWidth_));
    painter->setBrush(isHighlighted_ ? QBrush(Qt::blue) : QBrush(color_));
    painter->drawEllipse(startPoint_, pointRadius_, pointRadius_);
}

bool Point::isPointNear(const QPointF &point) const
{
    return QLineF(startPoint_, point).length() <= hitRadius_;
}

void Point::highlightControlPoints(const QPointF &point)
{
    isHighlighted_ = isPointNear(point);
}
